/*
 ------------------------------------------------------------------------------
 Copyright (C) 2009-2011 Eternal Games.

 This file is part of the Eternal Tech source code.

 The Eternal Tech source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Eternal Tech source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Eternal Tech source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// math.h - Math library
//


#if !defined(__MATH_H__) || !INCLUDE_GUARDS
#define __MATH_H__


#define Min(x, y)					(((x) < (y)) ? (x) : (y))
#define Max(x, y)					(((x) > (y)) ? (x) : (y))

class mathMain {
public:
	// Takes a float and returns a float
	static float		Sin (float x);

	// ...
	static float		Tan (float x);

	// ...
	static float		ATan (float y, float x);

	// Computes x raised to the power y
	static float		Pow (float x, float y);

	// Variable convertion functions
	static byte			FloatToByte (float f);
	static int			FloatToInt (float f);

	// Variable clamping functions
	static float		ClampFloat (float value, float min, float max);
};

/*
 ==================
 mathMain::Sin
 ==================
*/
inline float mathMain::Sin (float x)
{
	return sinf(x);
}

/*
 ==================
 mathMain::Tan
 ==================
*/
inline float mathMain::Tan (float x)
{
	return tanf(x);
}

/*
 ==================
 mathMain::ATan
 ==================
*/
inline float mathMain::ATan (float y, float x)
{
	return atan2f(y, x);
}

/*
 ==================
 mathMain::Pow
 ==================
*/
inline float mathMain::Pow (float x, float y)
{
	return powf(x, y);
}

/*
 ==================
 mathMain::FloatToByte
 ==================
*/
inline byte mathMain::FloatToByte (float f)
{
	int		i;

	i = (int)f;

	if (i < 0)
		return 0;

	if (i > 255)
		return 255;

	return i;
}

/*
 ==================
 mathMain::FloatToInt
 ==================
*/
inline int mathMain::FloatToInt (float f)
{
	return (int)f;
}

/*
 ==================
 mathMain::ClampFloat
 ==================
*/
inline float mathMain::ClampFloat (float value, float min, float max)
{
	if (value < min)
		return min;

	if (value > max)
		return max;

	return value;
}


#else
FILE_WARNING
#endif   // __MATH_H__